//
//  ViewController.swift
//  SwiftDemo
//
//  Created by hfzhangzhang on 2018/3/16.
//  Copyright © 2018年 hfzhangzhang. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        zz_printLog("------自定义打印-----------")
        
        let path = Bundle.main.path(forResource: "demo", ofType: "json")
        let data = NSData(contentsOfFile: path!)
        
        do {
            let obj = try JSONDecoder().decode(Obj.self, from: data! as Data)
            let value = obj.menu.popup.menuItem[0].value
            print(value)
        } catch {
            print("出错啦：\(error)")
        }
        
    }

}



struct Obj: Codable {
    let menu: Menu
    struct Menu: Codable {
        let id: String
        let value: String
        let popup: Popup
    }
    
    struct Popup: Codable {
        let menuItem: [MenuItem]
        enum CodingKeys: String, CodingKey {
            case menuItem = "menuitem"
        }
    }
    
    struct MenuItem: Codable {
        let value: String
        let onClick: String
        
        enum CodingKeys: String, CodingKey {
            case value
            case onClick = "onclick"
        }
    }
}
